﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Security.Cryptography;

public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("<script>alert('订票成功')</script>");
    }
    protected void ButtonSubmit_Click1(object sender, EventArgs e)
    {
        user user = new user();
        if (user.checkLogin(TextBoxLogin.Text.Trim()))
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "success", "alert(\"该登录名已存在\"); ", true);
            return;
        }
        user.name = TextBoxName.Text;
        user.userLogin = TextBoxLogin.Text;
        SHA1CryptoServiceProvider sha1csp = new SHA1CryptoServiceProvider();
        byte[] src = System.Text.Encoding.UTF8.GetBytes(TextBoxPassword.Text);
        byte[] des = sha1csp.ComputeHash(src);//加密后的密码
        user.password = Convert.ToBase64String(des);
        user.idcard = TextBoxIdcard0.Text;
        user.birthday = DateTime.ParseExact(TextBoxAddress1.Text, "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture); ;
        user.sex = RadioButtonList1.SelectedValue;
        user.homeUrl = TextBoxAddress3.Text;
        user.email = TextBoxEmail.Text;
        user.userInfo = TextBoxInfo.Text;
        user.address = TextBoxAddress.Text;
        user.telephone = TextBoxAddress2.Text;
        user.registTime = DateTime.Now;

        user user1 = new user();

        System.Diagnostics.Debug.Write("注册");
        bool result = user1.register(user);
        if (result)
        {
            System.Diagnostics.Debug.Write("注册成功");

            //user.login(TextBoxLogin.Text, TextBoxPassword.Text);
            Session["user_login"] = TextBoxLogin.Text;
            Session["user_id"] = user.id;
            Session["user_name"] = user.name;
            Session["user"] = user;
            Session["user_status"] = 0;
            Response.Redirect("Default.aspx");
        }
    }


    protected void ButtonCancle_Click(object sender, System.EventArgs e)
    {
        //Response.AddHeader("Refresh", "0");
        Response.Write("<script>alert('订票成功')</script>");
    }


}